<template>
	<view class="salary-container">
		<view class="salary-content">
			<view v-if="payMoneyList.length > 0" class="product-list">
				<view v-for="(item, index) in payMoneyList" :key="index" class="product-card">
					<view class="product-header">
						<view class="product-name">
							<text class="name-text">{{ getTypeName(item.type) }}</text>
							<text class="name-tag" :class="{'auto-tag': item.autointo === 1}">{{ item.autointo === 1 ? '自动转入' : '手动转入' }}</text>
						</view>
						<!-- <view class="product-status" :class="{'status-active': item.autointo === 1}">
							{{ item.autointo === 1 ? '自动' : '手动' }}
						</view> -->
					</view>

					<view class="product-body">
						<view class="income-info">
							<view class="income-rate">
								<text class="rate-symbol">¥</text>
								<text class="rate-value">{{ item.monthmoney }}</text>
							</view>
							<text class="rate-label">每月金额设定</text>
						</view>

						<view class="product-details">
							<view class="detail-item">
								<text class="detail-label">投资期限</text>
								<text class="detail-value">{{ item.investerm }}</text>
							</view>
						</view>
					</view>

					<view class="product-footer">
						<u-button type="primary" shape="circle" @click="handleBuy(item)" class="buy-btn">
							<text class="btn-text">立即投资</text>
						</u-button>
					</view>
				</view>
			</view>

			<u-empty v-else mode="data" text="很抱歉！暂时还没有工资理财向您推荐"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			payMoneyList: []
		}
	},
	onReady() {
		this.getPayMoneyList()
	},
	methods: {
		getPayMoneyList() {
			uni.request({
				url: '/api/bf/salary/list',
				method: 'GET',
			}).then(res => {
				this.payMoneyList = res.data.payMoneyList
			})
		},
		getTypeName(type) {
			return type === 1 ? '国债' : '期货'
		},
		handleBuy(item) {
			const name = this.getTypeName(item.type)
			const user = uni.getStorageSync('user')
			uni.showModal({
				title: '提示',
				content: `确定买入该${name}吗？`,
				success: (res) => {
					if (res.confirm) {
						uni.request({
							url: '/api/bf/salary/buyPayMoney',
							method: 'POST',
							data: {
								payMoneyId: item.id,
								user: user
							},
							success: (result) => {
								if (result.statusCode === 200) {
									uni.showToast({
										title: '买入成功',
										icon: 'success'
									})
								} else {
									uni.showToast({
										title: '买入失败',
										icon: 'error'
									})
								}
							}
						})
					}
				}
			})
		}
	}
}
</script>

<style scoped lang="scss">
.salary-container {
	padding: 20rpx;
	background-color: #f8f9fc;
	min-height: 100vh;

	.salary-content {
		padding: 0 20rpx;
	}

	.product-list {
		display: flex;
		flex-direction: column;
		gap: 24rpx;
	}

	.product-card {
		background: linear-gradient(135deg, #ffffff 0%, #f8f9fc 100%);
		border-radius: 24rpx;
		padding: 32rpx;
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.05);
		transition: all 0.3s ease;
		
		&:active {
			transform: scale(0.98);
		}

		.product-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 24rpx;

			.product-name {
				display: flex;
				align-items: center;
				gap: 16rpx;

				.name-text {
					font-size: 36rpx;
					font-weight: bold;
					color: #333;
					position: relative;
					
					&::after {
						content: '';
						position: absolute;
						bottom: -4rpx;
						left: 0;
						width: 100%;
						height: 4rpx;
						background: linear-gradient(90deg, #2979ff, #36cfc9);
						border-radius: 2rpx;
					}
				}

				.name-tag {
					font-size: 24rpx;
					color: #666;
					background-color: #f0f2f5;
					padding: 4rpx 16rpx;
					border-radius: 20rpx;
					
					&.auto-tag {
						color: #2979ff;
						background-color: rgba(41, 121, 255, 0.1);
					}
				}
			}

			.product-status {
				font-size: 24rpx;
				color: #999;
				background-color: #f0f2f5;
				padding: 4rpx 16rpx;
				border-radius: 20rpx;
				
				&.status-active {
					color: #52c41a;
					background-color: rgba(82, 196, 26, 0.1);
				}
			}
		}

		.product-body {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 32rpx;
			padding: 20rpx;
			background-color: #f8f9fc;
			border-radius: 16rpx;

			.income-info {
				text-align: center;

				.income-rate {
					display: flex;
					align-items: baseline;
					margin-bottom: 8rpx;

					.rate-symbol {
						font-size: 32rpx;
						color: #ff4d4f;
						margin-right: 4rpx;
					}

					.rate-value {
						font-size: 56rpx;
						font-weight: bold;
						color: #ff4d4f;
					}
				}

				.rate-label {
					font-size: 24rpx;
					color: #999;
				}
			}

			.product-details {
				display: flex;
				flex-direction: column;
				gap: 12rpx;

				.detail-item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 8rpx 16rpx;
					background-color: #fff;
					border-radius: 12rpx;

					.detail-label {
						font-size: 24rpx;
						color: #999;
					}

					.detail-value {
						font-size: 24rpx;
						color: #333;
						font-weight: 500;
					}
				}
			}
		}

		.product-footer {
			display: flex;
			justify-content: center;

			.buy-btn {
				width: 80%;
				height: 80rpx;
				background: linear-gradient(90deg, #2979ff, #36cfc9);
				border: none;
				box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.2);
				
				.btn-text {
					font-size: 32rpx;
					font-weight: bold;
				}
			}
		}
	}
}
</style>
